//
//  VoiceButtonView.m
//  tcpoctest
//
//  Created by apple on 13-7-16.
//  Copyright (c) 2013年 gump. All rights reserved.
//

#import "VoiceButtonView.h"

@implementation VoiceButtonView

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.multipleTouchEnabled = YES;
    }
    return self;
}

-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
    NSSet *allTouches = [event allTouches];
    UITouch *touch = [[allTouches allObjects] objectAtIndex:0];
    
    CGPoint location = [touch locationInView:self];
    
    if (location.y < -30) {
        if ([self.chatVCdelegate respondsToSelector:@selector(dismissVoiceTipsView)])
        {
            [self.chatVCdelegate performSelector:@selector(dismissVoiceTipsView) withObject:nil];
        }
    }
    else
    {
        if ([self.chatVCdelegate respondsToSelector:@selector(cancelLongPress:)])
        {
            [self.chatVCdelegate performSelector:@selector(cancelLongPress:) withObject:nil];
        }
    }
}

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    NSSet *allTouches = [event allTouches];
    UITouch *touch = [[allTouches allObjects] objectAtIndex:0];
    
    CGPoint location = [touch locationInView:self];
    
    if (CGRectContainsPoint(CGRectMake(40, 0, 240, CHATVIEW_VOICEBAR_HEIGHT), location)) {
        if ([self.chatVCdelegate respondsToSelector:@selector(longPressed:)])
            [self.chatVCdelegate performSelector:@selector(longPressed:) withObject:nil];
    }
}

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
    NSSet *allTouches = [event allTouches];
    UITouch *touch = [[allTouches allObjects] objectAtIndex:0];
    
    CGPoint location = [touch locationInView:self];
    
    if (location.y < -30) {
        if ([self.chatVCdelegate respondsToSelector:@selector(setVoiceCannel)])
        {
            [self.chatVCdelegate performSelector:@selector(setVoiceCannel) withObject:nil];
        }
    }
    else
    {
        if ([self.chatVCdelegate respondsToSelector:@selector(setVoiceSuccee)])
        {
            [self.chatVCdelegate performSelector:@selector(setVoiceSuccee) withObject:nil];
        }
    }
    
    
}

@end
